import QtQuick 2.0

Item {

    id: msgManager

    property int idx: 0
    property var msgList: []


    function show(msg, type){
        if(msgList.length >= 10){
            console.log("显示队列满了，休息一下吧")
        }
        msgList.push({
                         "msg": msg,
                         "type": type,
                         "idx": idx
                     })
        idx += 1
        refresh()

    }
    function remove(idx){
        for(let i = 0; i < msgList.length; i ++){
            if(msgList[i]["idx"] === idx){
                msgList.splice(i, 1)
                break
            }
        }
        refresh()
    }

    function refresh(){
        let i
        for(i = 0; i < msgList.length; i ++){
            repeater.itemAt(i).visible = true
            repeater.itemAt(i).idx = msgList[i]["idx"]
            repeater.itemAt(i).text = msgList[i]["msg"]
            repeater.itemAt(i).type = msgList[i]["type"]
        }for( ; i < 10; i ++){
            repeater.itemAt(i).visible = false
        }
    }
    width: parent.width


    Repeater{
        id: repeater
        model: 10
        Message{
            y: index * 40*dp
            visible: false
        }
    }




}
